package model;

// Generated 25-Nov-2013 20:54:41 by Hibernate Tools 4.0.0

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import static javax.persistence.GenerationType.IDENTITY;

import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

/**
 * Address generated by hbm2java
 */
@Entity
@Table(name = "address")
public class Address implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1691307502607007200L;
	private Integer addressId;
	private String street;
	private int buildingNumber;
	private City city;
	private Set<UserAddressHistory> userAddressHistories = new HashSet<UserAddressHistory>(
			0);

	public Address() {
	}

	public Address(Integer addressId, String street, int buildingNumber,
			City city, Set<UserAddressHistory> userAddressHistories) {
		super();
		this.addressId = addressId;
		this.street = street;
		this.buildingNumber = buildingNumber;
		this.city = city;
		this.userAddressHistories = userAddressHistories;
	}

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "address_id", unique = true, nullable = false)
	public Integer getAddressId() {
		return this.addressId;
	}

	public void setAddressId(Integer addressId) {
		this.addressId = addressId;
	}

	@Column(name = "street", nullable = false)
	public String getStreet() {
		return this.street;
	}

	public void setStreet(String street) {
		this.street = street;
	}

	@Column(name = "building_number", nullable = false)
	public int getBuildingNumber() {
		return this.buildingNumber;
	}

	public void setBuildingNumber(int buildingNumber) {
		this.buildingNumber = buildingNumber;
	}

	@OneToMany(mappedBy = "address")
	@LazyCollection(LazyCollectionOption.FALSE)
	public Set<UserAddressHistory> getUserAddressHistories() {
		return this.userAddressHistories;
	}

	public void setUserAddressHistories(
			Set<UserAddressHistory> userAddressHistories) {
		this.userAddressHistories = userAddressHistories;
	}

	@ManyToOne
	@LazyCollection(LazyCollectionOption.FALSE)
	@JoinColumn(name = "city_id", nullable = false)
	public City getCity() {
		return city;
	}

	public void setCity(City city) {
		this.city = city;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + buildingNumber;
		result = prime * result + ((city == null) ? 0 : city.hashCode());
		result = prime * result + ((street == null) ? 0 : street.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Address other = (Address) obj;
		if (buildingNumber != other.buildingNumber)
			return false;
		if (city == null) {
			if (other.city != null)
				return false;
		} else if (!city.equals(other.city))
			return false;
		if (street == null) {
			if (other.street != null)
				return false;
		} else if (!street.equals(other.street))
			return false;
		return true;
	}

}
